/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.account.Key.DataSourceBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.MailConstants;
/*     */ import com.zimbra.common.soap.SoapFaultException;
/*     */ import com.zimbra.common.util.SystemUtil;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DataSource;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.datasource.DataSourceManager;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.type.DataSourceType;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestDataSource
/*     */   extends MailDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException, SoapFaultException
/*     */   {
/*  42 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  43 */     Provisioning prov = Provisioning.getInstance();
/*  44 */     Account account = getRequestedAccount(zsc);
/*     */     
/*  46 */     if (!canModifyOptions(zsc, account)) {
/*  47 */       throw ServiceException.PERM_DENIED("can not modify options");
/*     */     }
/*  49 */     Map<String, Object> testAttrs = new HashMap();
/*  50 */     String testId = "TestId";
/*     */     
/*     */ 
/*  53 */     Element eDataSource = CreateDataSource.getDataSourceElement(request);
/*  54 */     DataSourceType type = DataSourceType.fromString(eDataSource.getName());
/*     */     
/*  56 */     String id = eDataSource.getAttribute("id", null);
/*  57 */     String password = null;
/*  58 */     DataSource dsOrig; if (id != null)
/*     */     {
/*  60 */       dsOrig = prov.get(account, Key.DataSourceBy.id, id);
/*  61 */       Map<String, Object> origAttrs = dsOrig.getAttrs();
/*  62 */       for (String key : origAttrs.keySet()) {
/*  63 */         if (key.equals("zimbraDataSourcePassword")) {
/*  64 */           password = dsOrig.getDecryptedPassword();
/*     */         } else {
/*  66 */           testAttrs.put(key, dsOrig.getAttr(key));
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*  73 */     String value = eDataSource.getAttribute("host", null);
/*  74 */     if (value != null) {
/*  75 */       testAttrs.put("zimbraDataSourceHost", value);
/*     */     }
/*  77 */     value = eDataSource.getAttribute("port", null);
/*  78 */     if (value != null) {
/*  79 */       testAttrs.put("zimbraDataSourcePort", value);
/*     */     }
/*  81 */     value = eDataSource.getAttribute("connectionType", null);
/*  82 */     if (value != null) {
/*  83 */       testAttrs.put("zimbraDataSourceConnectionType", value);
/*     */     }
/*  85 */     value = eDataSource.getAttribute("username", null);
/*  86 */     if (value != null) {
/*  87 */       testAttrs.put("zimbraDataSourceUsername", value);
/*     */     }
/*  89 */     value = eDataSource.getAttribute("password", null);
/*  90 */     if (value != null) {
/*  91 */       password = value;
/*     */     }
/*  93 */     value = eDataSource.getAttribute("leaveOnServer", null);
/*  94 */     if (value != null) {
/*  95 */       testAttrs.put("zimbraDataSourceLeaveOnServer", value.toUpperCase());
/*     */     }
/*  97 */     value = eDataSource.getAttribute("l", null);
/*  98 */     if (value != null) {
/*  99 */       testAttrs.put("zimbraDataSourceFolderId", value);
/*     */     }
/*     */     
/* 102 */     if (password != null)
/*     */     {
/*     */ 
/*     */ 
/* 106 */       testAttrs.put("zimbraDataSourcePassword", DataSource.encryptData(testId, password));
/*     */     }
/*     */     
/*     */ 
/* 110 */     value = eDataSource.getAttribute("importClass", DataSourceManager.getDefaultImportClass(type));
/* 111 */     if (value != null) {
/* 112 */       testAttrs.put("zimbraDataSourceImportClassName", value);
/*     */     }
/*     */     
/*     */ 
/* 116 */     ModifyDataSource.processCommonOptionalAttrs(testAttrs, eDataSource);
/*     */     
/*     */ 
/* 119 */     DataSource ds = new DataSource(account, type, "Test", testId, testAttrs, null);
/* 120 */     Element response = zsc.createElement(MailConstants.TEST_DATA_SOURCE_RESPONSE);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 129 */     eDataSource = response.addElement(type.toString());
/*     */     
/* 131 */     String error = null;
/*     */     try {
/* 133 */       DataSourceManager.test(ds);
/*     */     } catch (ServiceException x) {
/* 135 */       Throwable t = SystemUtil.getInnermostException(x);
/* 136 */       error = t.getMessage();
/* 137 */       if (error == null)
/* 138 */         error = "datasource test failed";
/*     */     }
/* 140 */     if (error == null) {
/* 141 */       eDataSource.addAttribute("success", true);
/*     */     } else {
/* 143 */       eDataSource.addAttribute("success", false);
/* 144 */       eDataSource.addAttribute("error", error);
/*     */     }
/*     */     
/* 147 */     return response;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/TestDataSource.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */